package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Test09 {
    public static void main(String[] args) {
//
        //txt文件内容->List
        //单步调试
        //点最左边加断点
        List<Book> books = new ArrayList<>();

        String path = "E:\\book.txt";
        String path1 = "E:\\book1.txt";

        BufferedReader reader = null;
        BufferedWriter writer = null;


        try {
            reader = new BufferedReader(new FileReader(path));


            String line = null;
            while ((line = reader.readLine()) != null) {

                String[] str = line.split("\t");
                Book book = new Book();
                book.bookNo = Integer.parseInt(str[0]);
                book.bookName = str[1];
                book.version = str[2];
                book.price = Double.parseDouble(str[3]);
                book.sales = Double.parseDouble(str[4]);

                books.add(book);

            }

            int i = 1;
            for (Book b : books) {

                if (i == 3) {
                    b.price = b.price + 20;
                }

                if (i == 4) {

                    b.price = b.price + 30;
                }
                i++;
            }

            writer = new BufferedWriter(new FileWriter(path1));

            for (Book b : books) {

                writer.write(b.bookNo + " " + b.bookName);
                writer.newLine();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
